from django.db import models

# Create your models here.

# 课程
class Project(models.Model):
    STATUS_CHOICES=[(1,'未开始'),(2,'进行中'),(3,'已结束')]
    name=models.CharField(max_length=50,unique=True)
    status=models.IntegerField(choices=STATUS_CHOICES)
    desc=models.TextField()
    createtime=models.DateTimeField(auto_now_add=True)

# 个人
class Person(models.Model):
    GENDER_CHOICES=[('男','Male'),('女','Female')]
    name=models.CharField(max_length=20,unique=True)
    age=models.IntegerField(default=18)
    # GENDER_CHOICES定义了性别选项的元组列表
    gender=models.CharField(max_length=20,choices=GENDER_CHOICES)

# 两表关联   地址
class Address(models.Model):
    #OneToOneField一对一关系  related_name用于定义反向查询的名称
    person=models.OneToOneField(Person,on_delete=models .CASCADE,related_name='address')
    city=models.CharField(max_length=20)
    town=models.CharField(max_length=20)
    village=models.CharField(max_length=20)
    detailaddress=models.CharField(max_length=20)

# 作者表
class Author(models.Model):
    GENDER_CHOICES=[("F","女"),("M","男")]
    name=models.CharField(max_length=50,unique=True)
    age=models.IntegerField()
    gender=models.CharField(max_length=1,choices=GENDER_CHOICES)

# 书籍表
class Book(models.Model):
    name = models.CharField(max_length=50)
    # 注意!max_digits，DecimalField有小数价格,decimal_places=2保留小数点后两位
    price=models.DecimalField(max_digits=5,decimal_places=2)
    publisher=models.CharField(max_length=50,null=False)
    # 数据库会变名字author_id
    author=models.ForeignKey(Author,on_delete=models.CASCADE,related_name='book')